<%-- 
    Document   : manageBook
    Created on : Oct 8, 2012, 6:53:53 PM
    Author     : Nhan
--%>
<%@ page import="java.util.*" %>

<%@page import="com.Checker"%>
<%@page import="com.Book"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Manage Book Page</title>
    </head>
    <body>
        <form action="../centralUnit?action=insertBook">
            <fieldset>
                <legend>Insert Book Panel</legend>
                <table>
                    <tr>
                        <td>Book Title: </td>
                        <td><input type="text" name="bTitle" value="" size="" /></td>
                    </tr>
                    <tr>
                        <td>Image Description</td>
                        <td><input type="text" name="bImage" value="" size="" /></td>
                    </tr>
                    <tr>
                        <td>Author</td>
                        <td><input type="text" name="bAuthor" value="" size="" /></td>
                    </tr>
                    <tr>
                        <td>Type</td>
                        <td><input type="text" name="bType" value="" size="" /></td>
                    </tr>
                    <tr>
                        <td>Price</td>
                        <td><input type="text" name="bPrice" value="" size="" /></td>
                    </tr>
                    <tr>
                        <td><input type="submit" name="action" value="Insert" size="" /></td>
                        <td><input type="reset" value="Reset" /></td>
                    </tr>
                </table>
            </fieldset>
            
        </form>
        <table border="1" cellspacing="0">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Book ID</th>
                    <th>Title</th>
                    <th>Image</th>
                    <th>Author</th>
                    <th>Type</th>
                    <th>Price</th>
                </tr>
            </thead>
            <tbody>
                <%
                    ArrayList<Book> searhResult = Checker.getAllBook();
                    int index = 0;
                    if (searhResult.size() != 0) {
                        for (Book book : searhResult) {
                            index++;
                            int id = book.getId();
                            String title = book.getTitle();
                            String author = book.getAuthor();
                            String image = book.getImage();
                            String type = book.getType();
                            float price = book.getPrice();
                            String url = "../centralUnit?action=viewBook&bookID=" + id;
                            String encodedUrl = response.encodeRedirectURL(url);
                %>

                <tr>
                    <td><%= index%></td>
                    <td><%= id %></td>
                    <td><a href="<%= encodedUrl %>"><%= title %></a></td>
                    <td><img src="../images/<%= image %>" alt="Images Description for <%= title %>" height="60px" width="50px" /></td>
                    <td><%= author %></td>
                    <td><%= type %></td>
                    <td><%=price %></td>

                     <td>
                        <form action="../centralUnit" method="GET">
                           <input type="hidden" name="bookIDToUpdate" value="<%= id %>" />
                           <input type="submit" name="action" value="Update" size="" />
                        </form>
                    </td>
                    <td>
                        <form action="../centralUnit" method="GET">
                           <input type="hidden" name="bookIDToDelete" value="<%= id %>" />
                           <input type="submit" name="action" value="Delete" size="" />
                        </form>
                    </td>

                </tr>
                <% }
                           } else {%>

                <tr><td colspan="6"><h3>0 result, Please try another keyword!</h3></tr>

                <% }

                %>
            </tbody>
        </table>
    </body>
</html>
